<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-card>
        <el-form-item label="项目名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入项目名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="项目代码" prop="code">
          <el-input
            v-model="queryParams.code"
            placeholder="请输入项目代码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="启动日期" prop="startTime">
          <el-date-picker clearable size="small" style="width:100%;" v-model="queryParams.startTime" type="date" value-format="yyyy-MM-dd" placeholder="选择启动日期"></el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="竣工日期" prop="endTime">
          <el-date-picker clearable size="small" style="width:100%;" v-model="queryParams.endTime" type="date" value-format="yyyy-MM-dd" placeholder="选择竣工日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="项目金额" prop="totalInvest">
          <el-input
            v-model="queryParams.totalInvest"
            placeholder="请输入项目金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <el-form-item label="项目状态 " prop="status">
          <el-select v-model="queryParams.status" placeholder="请选择项目状态 " clearable size="small">
            <el-option
              v-for="(dict,index) in dict.type.sys_project_status"
              :key="'b'+index"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-card>
    </el-form>

    <el-card style="margin-top:10px;">
      <el-table v-loading="loading" :data="projectList" border>
        <el-table-column label="项目名称" align="center" prop="name" />
        <el-table-column label="项目代码" align="center" prop="code" />
        <el-table-column label="启动日期" align="center" prop="startTime" />
        <el-table-column label="竣工日期" align="center" prop="endTime" />
        <el-table-column label="负责人" align="center" prop="chargerName" />
        <el-table-column label="负责部门" align="center" prop="deptName" />
        <el-table-column label="项目金额(万元)" align="center" prop="totalInvest">
          <template slot-scope="scope">
            <span style="color:blue;">{{ scope.row.totalInvest | moneyFormat }}</span>
          </template>
        </el-table-column>
        <el-table-column label="施工单位" align="center" prop="constructDept" />
        <el-table-column label="监理单位" align="center" prop="supervisor" />
        <el-table-column label="施工联系人" align="center" prop="contactPerson" />
        <el-table-column label="联系方式" align="center" prop="contactPhone" />
        <el-table-column label="项目状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_project_status" v-if="scope.row.status==1" style="color:red;" :value="scope.row.status"/>
            <dict-tag :options="dict.type.sys_project_status" v-if="scope.row.status==2" style="color:blue;" :value="scope.row.status"/>
            <dict-tag :options="dict.type.sys_project_status" v-if="scope.row.status==3" style="color:green;" :value="scope.row.status"/>
            <dict-tag :options="dict.type.sys_project_status" v-if="scope.row.status==4" style="color:gray;" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-dropdown :hide-on-click="false">
              <span class="el-dropdown-link" style="color:blue;">
                更多操作<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleView(scope.row)"><i class="el-icon-document"></i>项目详情</el-dropdown-item>
                <el-dropdown-item style="color:blue;" @click.native="handleUpdate(scope.row)"><i class="el-icon-edit-outline"></i>项目修改</el-dropdown-item>
                <el-dropdown-item style="color:green;" v-if="scope.row.status==1" @click.native="handleStart(scope.row)"><i class="el-icon-s-promotion"></i>项目启动</el-dropdown-item>
                <el-dropdown-item style="color:orange;" v-if="scope.row.status==2" @click.native="handleFinish(scope.row)"><i class="el-icon-s-help"></i>项目竣工</el-dropdown-item>
                <el-dropdown-item style="color:gray;" v-if="scope.row.status==1" @click.native="handleNullify(scope.row)"><i class="el-icon-delete"></i>项目作废</el-dropdown-item>
                <el-dropdown-item style="color:blue;" v-if="scope.row.status==3||scope.row.status==4" @click.native="handleRestart(scope.row)"><i class="el-icon-refresh"></i>重回施工</el-dropdown-item>
                <el-dropdown-item style="color:red;" v-if="scope.row.status!=1" @click.native="handleInit(scope.row)"><i class="el-icon-timer"></i>回到未动工</el-dropdown-item>
                <el-dropdown-item style="color:red;" v-if="scope.row.status==4" @click.native="handleDelete(scope.row)"><i class="el-icon-delete-solid"></i>项目删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 详情 -->
    <el-dialog :title="vTitle" :visible.sync="vOpen" width="70%" append-to-body>
      <el-card style="margin-top:-30px">
        <div slot="header" class="clearfix">
          <center><span style="font-weight:bold;font-size:18px;">{{ projectDetail.name }}</span></center>
        </div>
        <el-descriptions :column="2" border>
          <el-descriptions-item label="项目编码" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.projectNo }}
          </el-descriptions-item>
          <el-descriptions-item label="项目代码" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.code }}
          </el-descriptions-item>
          <el-descriptions-item label="施工单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.constructDept }}
          </el-descriptions-item>
          <el-descriptions-item label="监理单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.supervisor }}
          </el-descriptions-item>
          <el-descriptions-item label="启动日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.startTime }}
          </el-descriptions-item>
          <el-descriptions-item label="竣工日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.endTime }}
          </el-descriptions-item>
          <el-descriptions-item label="负责人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.chargerName }}
          </el-descriptions-item>
          <el-descriptions-item label="负责部门" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.deptName }}
          </el-descriptions-item>
          <el-descriptions-item label="施工联系人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.contactPerson }}
          </el-descriptions-item>
          <el-descriptions-item label="联系方式" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.contactPhone }}
          </el-descriptions-item>
          <el-descriptions-item label="施工地点" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.constructSite }}
          </el-descriptions-item>
          <el-descriptions-item label="项目状态" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <dict-tag :options="dict.type.sys_project_status" :value="projectDetail.status"/>
          </el-descriptions-item>
          <el-descriptions-item label="创建人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.creator }}
          </el-descriptions-item>
          <el-descriptions-item label="创建时间" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <span>{{ parseTime(projectDetail.createTime, '{y}-{m}-{d}') }}</span>
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions :column="1" border style="margin-top:-2px;">
          <el-descriptions-item label="项目金额" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ projectDetail.totalInvest | moneyFormat }} <span style="margin-left:10px;">万元</span>
          </el-descriptions-item>
          <el-descriptions-item label="项目描述" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ projectDetail.describe }}
          </el-descriptions-item>
          <el-descriptions-item label="补充说明" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ projectDetail.remark }}
          </el-descriptions-item>
        </el-descriptions>
      </el-card>
      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">项目图片</span>
        </div>
        <new-preview v-if="projectDetail.contractAttach!=null" :src="projectDetail.contractAttach" :width="200" :height="200" />
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">项目附件</span>
        </div>
        <file-upload-show :fileList_show="fileList_show" />
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">工程信息</span>
        </div>
        <el-table v-if="engineer4ProjectDetailList.length>0" :data="engineer4ProjectDetailList" border>
          <el-table-column label="序号" align="center"  type="index" width="55"/>
          <el-table-column label="工程名称" align="center" prop="name" />
          <el-table-column label="工程代码" align="center" prop="code" />
          <el-table-column label="所属项目" align="center" prop="projectName" />
          <el-table-column label="工程金额(万元)" align="center" prop="costConstruction">
            <template slot-scope="scope">
              <span style="color:blue;">{{ scope.row.costConstruction | moneyFormat }}</span>
            </template>
          </el-table-column>
          <el-table-column label="施工单位" align="center" prop="ownerDept" />
          <el-table-column label="监理单位" align="center" prop="supervisor" />
          <el-table-column label="工程状态" align="center" prop="status">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==1" style="color:red;" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==2" style="color:blue;" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==3" style="color:green;" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==4" style="color:gray;" :value="scope.row.status"/>
            </template>
          </el-table-column>
        </el-table>
        <span v-if="engineer4ProjectDetailList.length==0" style="color:red">暂未挂接工程</span>
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">子工程信息</span>
        </div>
        <el-table v-if="subEngineer4ProjectDetail.length>0" :data="subEngineer4ProjectDetail" border>
          <el-table-column label="序号" align="center"  type="index" width="55"/>
          <el-table-column label="名称" align="center" prop="name" />
          <el-table-column label="代码" align="center" prop="code" />
          <el-table-column label="类型" align="center" prop="engineerTypeName">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_sub_engineer_type" :value="scope.row.engineerType"/>
            </template>
          </el-table-column>
          <el-table-column label="所属工程" align="center" prop="engineerName" />
          <el-table-column label="所属项目" align="center" prop="projectName" />
          <el-table-column label="金额(万元)" align="center" prop="costConstruction">
            <template slot-scope="scope">
              <span style="color:blue;">{{ scope.row.costConstruction | moneyFormat }}</span>
            </template>
          </el-table-column>
          <el-table-column label="施工单位" align="center" prop="ownerDept" />
          <el-table-column label="监理单位" align="center" prop="supervisor" />
          <el-table-column label="状态" align="center" prop="status">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==1" style="color:red;" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==2" style="color:blue;" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==3" style="color:green;" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==4" style="color:gray;" :value="scope.row.status"/>
            </template>
          </el-table-column>
        </el-table>
        <span v-if="subEngineer4ProjectDetail.length==0" style="color:red">暂无子工程数据</span>
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">项目数据集</span>
        </div>
        <el-table :data="projectDatasetsList" border>
          <el-table-column label="序号" align="center" type="index" />
          <el-table-column label="名称" align="center" prop="name" />
          <el-table-column label="编码" align="center" prop="code" />
          <el-table-column label="类型" align="center" prop="type" width="120">
          <template slot-scope="scope">
              <dict-tag :options="dict.type.sy_dataset_type" :value="scope.row.type"/>
          </template>
          </el-table-column>
          <el-table-column label="状态" align="center" prop="status" width="120">
          <template slot-scope="scope">
              <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==0" style="color:blue" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==1" style="color:green" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==2" style="color:red" :value="scope.row.status"/>
          </template>
          </el-table-column>
          <el-table-column label="创建人" align="center" prop="creator" width="120" />
          <el-table-column label="创建日期" align="center" prop="createTime" width="120">
          <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
          </el-table-column>
          <el-table-column label="发布人员" align="center" prop="publisher" width="120" />
          <el-table-column label="发布日期" align="center" prop="publishTime" width="120">
          <template slot-scope="scope">
              <span>{{ parseTime(scope.row.publishTime, '{y}-{m}-{d}') }}</span>
          </template>
          </el-table-column>
        </el-table>
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">项目待办事项</span>
        </div>
        <el-table :data="itemsList" border>
          <el-table-column label="序号" align="center" type="index" />
          <el-table-column label="事项标题" align="left" prop="itemName" />
          <el-table-column label="发起人" align="center" prop="createName" width="100" />
          <el-table-column label="发起日期" align="center" prop="createTime" width="120">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="当前跟进人" align="center" prop="followupName" width="120">
            <template slot-scope="scope">
              <span v-if="scope.row.status==2">-</span>
              <span v-if="scope.row.status!=2">{{scope.row.followupName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="跟进状态" align="center" prop="status" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.status==0" style="color:blue;">待跟进</span>
              <span v-if="scope.row.status==1" style="color:red;">跟进中</span>
              <span v-if="scope.row.status==2" style="color:green;">已结束</span>
            </template>
          </el-table-column>
          <el-table-column label="截止日期" align="center" prop="deadTime" width="120" />
        </el-table>
      </el-card>

      <div slot="footer" class="dialog-footer" v-if="startProject==true||finishProject==true||nullifyProject==true||deleteProject==true||restartProject==true||initProject==true">
        <el-button type="success" v-show="startProject" @click="processStartProject(projectDetail)">项目启动</el-button>
        <el-button type="warning" v-show="finishProject" @click="processFinishProject(projectDetail)">项目竣工</el-button>
        <el-button type="info" v-show="nullifyProject" @click="processNullifyProject(projectDetail)">项目作废</el-button>
        <el-button type="primary" v-show="restartProject" @click="processRestartProject(projectDetail)">重回施工</el-button>
        <el-button type="danger" v-show="initProject" @click="processInitProject(projectDetail)">回到未动工</el-button>
        <el-button type="danger" v-show="deleteProject" @click="processDeleteProject(projectDetail)">项目删除</el-button>
      </div>
    </el-dialog>
    <!-- 修改 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-card style="margin-top:-2px;">
            <div slot="header" class="clearfix">
              <span style="color:#329dff;font-weight:bold;font-size:14px;">项目信息</span>
            </div>
            <el-row>
                <el-col :span="12">
                  <el-form-item label="项目编码" prop="projectNo">
                    <el-input v-model="form.projectNo" disabled />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目代码" prop="code">
                    <el-input v-model="form.code" />
                  </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                  <el-form-item label="项目名称" prop="name">
                    <el-input v-model="form.name" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目金额" prop="totalInvest">
                    <el-input-number style="width:95%;color:red;" v-model="form.totalInvest" :controls="false" :precision="4" /><span style="color:blue;margin-left:5px;">万元</span>
                  </el-form-item>
                </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="启动日期" prop="startTime">
                  <el-date-picker clearable size="small" style="width:100%;" v-model="form.startTime" type="date" value-format="yyyy-MM-dd" placeholder="选择启动日期"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="竣工日期" prop="endTime">
                  <el-date-picker clearable size="small" style="width:100%;" v-model="form.endTime" type="date" value-format="yyyy-MM-dd" placeholder="选择竣工日期"></el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="负责人" prop="chargerId">
                  <el-select v-model="form.chargerId" filterable clearable placeholder="请选择负责人" style="width:100%;">
                    <el-option v-for="item in participants" :key="item.userId" :label="item.nickName" :value="item.userId"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="负责部门" prop="deptId">
                  <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择负责部门" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="施工单位" prop="constructDept">
                  <el-input v-model="form.constructDept" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="监理单位" prop="supervisor">
                  <el-input v-model="form.supervisor" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
              <el-form-item label="施工联系人" prop="contactPerson">
                <el-input v-model="form.contactPerson" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="联系方式" prop="contactPhone">
                  <el-input v-model="form.contactPhone" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="施工地点" prop="constructSite">
                  <el-input v-model="form.constructSite" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="项目描述" prop="describe">
                  <el-input type="textarea" v-model="form.describe" :rows="6"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="补充说明" prop="remark">
                  <el-input type="textarea" v-model="form.remark" :rows="6"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>

          <el-card style="margin-top:10px;">
            <div slot="header" class="clearfix">
              <span style="color:#329dff;font-weight:bold;font-size:14px;">挂接工程</span>
            </div>
            <el-table ref="table" :data="engineer4ProjectList" @selection-change="handleSelectionChange" :row-key="getRowKeys" border style="margin-top:10px;">
              <el-table-column type="selection" width="50" align="center" :selectable="selectable" />
              <el-table-column label="序号" align="center" type="index" width="55" />
              <el-table-column label="工程名称" align="center" prop="name" />
              <el-table-column label="工程代码" align="center" prop="code" />
              <el-table-column label="施工单位" align="center" prop="ownerDept" />
              <el-table-column label="监理单位" align="center" prop="supervisor" />
              <el-table-column label="工程状态" align="center" prop="status" width="80">
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==1" style="color:red;" :value="scope.row.status"/>
                  <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==2" style="color:blue;" :value="scope.row.status"/>
                  <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==3" style="color:green;" :value="scope.row.status"/>
                  <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==4" style="color:gray;" :value="scope.row.status"/>
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center" width="100">
                <template slot-scope="scope">
                  <el-button v-if="scope.row.hasProject==1" type="text" @click="unhookEngineer(scope.row)">解除挂接</el-button>
                </template>
              </el-table-column>
            </el-table>
            <br />
          </el-card>

          <el-card style="margin-top:10px;">
            <div slot="header" class="clearfix">
              <span style="color:#329dff;font-weight:bold;font-size:14px;">项目附件</span>
            </div>
            <el-row>
              <el-col :span="24">
                <el-form-item prop="contractAttach">
                  <image-upload-custom v-model="form.contractAttach" :limit="10000" :imageName="imageName"></image-upload-custom>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item prop="materialAttach">
                  <file-upload-custom
                    :fileSize="10000"
                    :attachName="attachOtherName"
                    :fileList_show="fileList_show"
                    v-model="form.materialAttach"
                    @addlist="fileList_show_add"
                    @deletlist="fileList_show_delet"
                  />
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProject,getProject,editProject,processStartProject,processFinishProject,processNullifyProject,processDeleteProject,processRestartProject,processInitProject } from "@/api/system/project";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listAllUser } from "@/api/system/user";
import { getEngineerList4Project,unhookEngineer,getEngineerList4ProjectDetail } from "@/api/system/engineer";
import { getSubEngineer4ProjectDetail } from "@/api/system/subengineer";
import { getBindProjectDatasets } from "@/api/system/dataset";
import { getItemListByItemParentId } from "@/api/system/items";

export default {
  name: "QueryProject",
  dicts: ['sys_project_status','sys_engineer_status','sys_sub_engineer_status','sys_sub_engineer_type','sy_dataset_status','sy_dataset_type'],
  components:{ Treeselect },
  data() {
    return {
      attachPdfName: '上传PDF',
      attachOtherName: '上传文件',
      imageName: '上传图片',
      participants: [],
      deptOptions: [],
      fileList_show:[],
      projectDetail: {},
      startProject: false,
      finishProject: false,
      nullifyProject: false,
      deleteProject: false,
      restartProject: false,
      initProject: false,
      moneyFormat: 4,
      engineer4ProjectList: [],
      engineer4ProjectDetailList: [],
      subEngineer4ProjectDetail: [],
      projectDatasetsList: [],
      itemsList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目信息表表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      vOpen: false,
      // 弹出层标题
      vTitle: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectNo: null,
        name: null,
        code: null,
        startTime: null,
        endTime: null,
        describe: null,
        status: null,
        chargerId: null,
        deptId: null,
        contactPerson: null,
        contactPhone: null,
        totalInvest: null,
        constructSite: null,
        supervisor: null,
        contractAttach: null,
        materialAttach: null,
        roleIds: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectNo: [
          { required: true, message: "项目编号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.listAllUser();
    this.getTreeselect();
  },
  methods: {
    unhookEngineer(row){
      let projectId = row.projectId;
      unhookEngineer(row).then(res => {
        if(res.code==200){
          this.getEngineerList4Project(projectId)
        }
      })
    },
    getRowKeys(row) {
      return row.uuid;
    },
    getEngineerList4Project(projectId){
      let query = {
        projectId:projectId
      };
      this.engineer4ProjectList = [];
      getEngineerList4Project(query).then(res =>{
        this.engineer4ProjectList = res.data;
        var that = this;
        that.$nextTick(() => {
          this.engineer4ProjectList.forEach((v, i) => {
            if (v.hasProject == 1) {
              this.$refs.table.toggleRowSelection(v, true);
            }
          });
        });
      })
    },
    /** 查询项目信息表列表 */
    getList() {
      this.loading = true;
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        uuid: null,
        projectNo: null,
        name: null,
        code: null,
        startTime: null,
        endTime: null,
        describe: null,
        status: null,
        chargerId: null,
        deptId: null,
        contactPerson: null,
        contactPhone: null,
        totalInvest: null,
        constructDept: null,
        constructSite: null,
        supervisor: null,
        contractAttach: null,
        materialAttach: null,
        roleIds: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        engineerIds: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.uuid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目信息";
    },
    handleView(row){
      this.fileList_show = [];
      this.projectDetail = {};
      getProject(row.uuid).then(res => {
        this.projectDetail = res.data;
        this.vOpen = true;
        this.vTitle = "项目详情";
        this.fileList_show = res.data.attachList;
        this.startProject = false;
        this.finishProject = false;
        this.nullifyProject = false;
        this.deleteProject = false;
        this.restartProject = false;
        this.initProject = false;
        this.getEngineerList4ProjectDetail({projectId:row.uuid});
        this.getSubEngineer4ProjectDetail({projectId:row.uuid});

        //获取数据集
        let query = {
          projectIds: row.uuid
        }
        getBindProjectDatasets(query).then(res =>{
          this.projectDatasetsList = [];
          this.projectDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    getSubEngineer4ProjectDetail(query){
      getSubEngineer4ProjectDetail(query).then(res =>{
        this.subEngineer4ProjectDetail = res.data;
      })
    },
    getEngineerList4ProjectDetail(query){
      getEngineerList4ProjectDetail(query).then(res =>{
        this.engineer4ProjectDetailList = res.data;
      })
    },
    handleRestart(row){
      this.fileList_show = [];
      this.projectDetail = {};
      getProject(row.uuid).then(res => {
        this.projectDetail = res.data;
        this.vOpen = true;
        this.vTitle = "项目详情";
        this.fileList_show = res.data.attachList;
        this.startProject = false;
        this.finishProject = false;
        this.nullifyProject = false;
        this.deleteProject = false;
        this.restartProject = true;
        this.initProject = false;
        this.getEngineerList4ProjectDetail({projectId:row.uuid});
        this.getSubEngineer4ProjectDetail({projectId:row.uuid});
        //获取数据集
        let query = {
          projectIds: row.uuid
        }
        getBindProjectDatasets(query).then(res =>{
          this.projectDatasetsList = [];
          this.projectDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    handleStart(row){
      this.fileList_show = [];
      this.projectDetail = {};
      getProject(row.uuid).then(res => {
        this.projectDetail = res.data;
        this.vOpen = true;
        this.vTitle = "项目详情";
        this.fileList_show = res.data.attachList;
        this.startProject = true;
        this.finishProject = false;
        this.nullifyProject = false;
        this.deleteProject = false;
        this.restartProject = false;
        this.initProject = false;
        this.getEngineerList4ProjectDetail({projectId:row.uuid});
        this.getSubEngineer4ProjectDetail({projectId:row.uuid});
        //获取数据集
        let query = {
          projectIds: row.uuid
        }
        getBindProjectDatasets(query).then(res =>{
          this.projectDatasetsList = [];
          this.projectDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    handleFinish(row){
      this.fileList_show = [];
      this.projectDetail = {};
      getProject(row.uuid).then(res => {
        this.projectDetail = res.data;
        this.vOpen = true;
        this.vTitle = "项目详情";
        this.fileList_show = res.data.attachList;
        this.startProject = false;
        this.finishProject = true;
        this.nullifyProject = false;
        this.deleteProject = false;
        this.restartProject = false;
        this.initProject = false;
        this.getEngineerList4ProjectDetail({projectId:row.uuid});
        this.getSubEngineer4ProjectDetail({projectId:row.uuid});
        //获取数据集
        let query = {
          projectIds: row.uuid
        }
        getBindProjectDatasets(query).then(res =>{
          this.projectDatasetsList = [];
          this.projectDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    handleNullify(row){
      this.fileList_show = [];
      this.projectDetail = {};
      getProject(row.uuid).then(res => {
        this.projectDetail = res.data;
        this.vOpen = true;
        this.vTitle = "项目详情";
        this.fileList_show = res.data.attachList;
        this.startProject = false;
        this.finishProject = false;
        this.nullifyProject = true;
        this.deleteProject = false;
        this.restartProject = false;
        this.initProject = false;
        this.getEngineerList4ProjectDetail({projectId:row.uuid});
        this.getSubEngineer4ProjectDetail({projectId:row.uuid});
        //获取数据集
        let query = {
          projectIds: row.uuid
        }
        getBindProjectDatasets(query).then(res =>{
          this.projectDatasetsList = [];
          this.projectDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    handleInit(row){
      this.fileList_show = [];
      this.projectDetail = {};
      getProject(row.uuid).then(res => {
        this.projectDetail = res.data;
        this.vOpen = true;
        this.vTitle = "项目详情";
        this.fileList_show = res.data.attachList;
        this.startProject = false;
        this.finishProject = false;
        this.nullifyProject = false;
        this.deleteProject = false;
        this.restartProject = false;
        this.initProject = true;
        this.getEngineerList4ProjectDetail({projectId:row.uuid});
        this.getSubEngineer4ProjectDetail({projectId:row.uuid});
        //获取数据集
        let query = {
          projectIds: row.uuid
        }
        getBindProjectDatasets(query).then(res =>{
          this.projectDatasetsList = [];
          this.projectDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.fileList_show = [];
      this.projectDetail = {};
      getProject(row.uuid).then(res => {
        this.projectDetail = res.data;
        this.vOpen = true;
        this.vTitle = "项目详情";
        this.fileList_show = res.data.attachList;
        this.startProject = false;
        this.finishProject = false;
        this.nullifyProject = false;
        this.deleteProject = true;
        this.restartProject = false;
        this.initProject = false;
        this.getEngineerList4ProjectDetail({projectId:row.uuid});
        this.getSubEngineer4ProjectDetail({projectId:row.uuid});
        //获取数据集
        let query = {
          projectIds: row.uuid
        }
        getBindProjectDatasets(query).then(res =>{
          this.projectDatasetsList = [];
          this.projectDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.fileList_show = [];
      getProject(row.uuid).then(res => {
        this.form = res.data;
        this.open = true;
        this.title = "修改项目信息";
        this.fileList_show = res.data.attachList;

        // 获取工程
        let query = {
          projectId: row.uuid
        };
        getEngineerList4Project(query).then(res =>{
          this.engineer4ProjectList = res.data;
          var that = this;
          that.$nextTick(() => {
            this.engineer4ProjectList.forEach((v, i) => {
              if (v.hasProject == 1) {
                this.$refs.table.toggleRowSelection(v, true);
              }
            });
          });
        })
      });
    },
    selectable(row, index) {
      if (row.hasProject == 1) {
        return false; // 禁用
      } else {
        return true; //不禁用
      }
    },
    listAllUser(){
      listAllUser().then(res =>{
        this.participants = res.data;
      })
    },
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 文件上传接收子组件值，同步（增）
    fileList_show_add(val){
      this.fileList_show = this.fileList_show.concat(val);
    },
    // 文件上传接收子组件值，同步（减）
    fileList_show_delet(val){
      this.fileList_show.splice(val, 1);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.ids.length>0){
            this.form.engineerIds = this.ids.join(",");
          }
          if (this.form.uuid != null) {
            editProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            editProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    processStartProject(row){
      this.$modal.confirm('是否确认启动项目 "' + row.name + '" ？').then(function() {
        return processStartProject(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("启动成功");
      }).catch(() => {});
    },
    processFinishProject(row){
      this.$modal.confirm('是否确认项目 "' + row.name + '" 竣工？').then(function() {
        return processFinishProject(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("竣工成功");
      }).catch(() => {});
    },
    processNullifyProject(row){
      this.$modal.confirm('是否确认作废项目 "' + row.name + '" ？').then(function() {
        return processNullifyProject(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("作废成功");
      }).catch(() => {});
    },
    processRestartProject(row){
      this.$modal.confirm('是否确认项目 "' + row.name + '" 重回施工？').then(function() {
        return processRestartProject(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("重回施工");
      }).catch(() => {});
    },
    processDeleteProject(row){
      this.$modal.confirm('是否确认删除项目 "' + row.name + '" ？').then(function() {
        return processDeleteProject(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    processInitProject(row){
      this.$modal.confirm('是否确认项目 "' + row.name + '" 回到未动工？').then(function() {
        return processInitProject(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("回到未动工成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/project/export', {
        ...this.queryParams
      }, `project_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
